//
//  AllCommunityTableCell.m
//  Bees
//
//  Created by NowYouCanSee on 2019/1/8.
//  Copyright © 2019 xiaohan. All rights reserved.
//

#import "AllCommunityTableCell.h"
#import "ChatroomModel.h"
@implementation AllCommunityTableCell
- (void)setModel:(ChatroomModel *)model{
    _model = model;
    self.jionBtn.selected = model.is_join;
    [self.iconV sd_setImageWithURL:String_To_URL(model.logo)];
    self.titleLab.text = model.name;
    [self.numBtn setTitle:[NSString stringWithFormat:@" %@",model.user_num] forState:UIControlStateNormal];;
}

- (void)setupUI{
//    number_of_person
    self.contentView.backgroundColor = UIColor.clearColor;
    self.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:self.iconV];
    [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(50.0f), AdaptedWidth(50.0f)));
        make.centerY.mas_equalTo(0);
        make.left.mas_equalTo(kNormalSpace);
    }];
    [self.contentView addSubview:self.titleLab];
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconV.mas_right).offset(AdaptedWidth(10));
        make.top.equalTo(self.iconV.mas_top).offset(AdaptedWidth(10));
    }];
    [self.contentView addSubview:self.numBtn];
    [self.numBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconV.mas_right).offset(AdaptedWidth(10));
        make.bottom.equalTo(self.iconV.mas_bottom).offset(AdaptedWidth(-5));
    }];
    [self.contentView addSubview:self.jionBtn];
    [self.jionBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-kNormalSpace);
        make.centerY.mas_equalTo(0);
        make.size.mas_equalTo(CGSizeMake(AdaptedWidth(77), AdaptedWidth(27)));
    }];
    ViewRadius(self.jionBtn, AdaptedWidth(13.5));
    kWeakSelf(self);
    [self.jionBtn addTapBlock:^(UIButton * _Nonnull btn) {
        !weakself.jionBtnClickBlock?:weakself.jionBtnClickBlock(weakself.model);
    }];
}
- (UIImageView*)iconV{
    if (!_iconV) {
        _iconV = [UIImageView new];
        ViewBorderRadius(_iconV, AdaptedWidth(13), 1, kLineColor);
    }
    return _iconV;
}

- (UILabel*)titleLab{
    if (!_titleLab) {
        _titleLab = [UILabel new];
        _titleLab.textColor = UIColor.blackColor;
        _titleLab.font = kBoldFont(16);
    }
    return _titleLab;
}

- (UIButton*)numBtn{
    if (!_numBtn) {
        _numBtn = [UIButton new];
        [_numBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateNormal];
        _numBtn.titleLabel.font = kDefaultFont(12);
        [_numBtn setImage:IMAGE_NAMED(@"number_of_person") forState:UIControlStateNormal];
    }
    return _numBtn;
}
- (UIButton*)jionBtn{
    if (!_jionBtn) {
        _jionBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_jionBtn setTitle:XLocalized(@"加入") forState:UIControlStateNormal];
        [_jionBtn setTitleColor:UIColorHex(#333333) forState:UIControlStateNormal];
        _jionBtn.titleLabel.font = kDefaultFont(13);
        [_jionBtn setBackgroundImage:[UIImage imageWithColor:kColorMain] forState:UIControlStateNormal];
        [_jionBtn setBackgroundImage:[UIImage imageWithColor:UIColorHex(#ECECEC)] forState:UIControlStateSelected];
        [_jionBtn setTitleColor:UIColorHex(#999999) forState:UIControlStateSelected];
        [_jionBtn setTitle:XLocalized(@"已加入") forState:UIControlStateSelected];
    }
    return _jionBtn;
}
@end
